package 剑指offer.zw_15_二进制中1的个数;

public class Solution {
    public static void main(String[] args) {
        int n = 11;
        int weight = hammingWeight(n);
        System.out.println(weight);
    }

    // you need to treat n as an unsigned value
    public static int hammingWeight(int n) {
        int ans = 0;
        while (n != 0) {
            ans++;
            n = n & (n - 1);
        }
        return ans;
    }
}
